import {request} from "./index.ts"

/**
 * 请求方法
 */
interface ProcessRequestInterface {
    get: Function;
    post: Function;
    put: Function;
    delete: Function;
}

/**
 * 其他值
 */
interface RequestOtherParamsType {
    /**
     * 是否加载中
     */
    isLoading?: boolean;
}

/**
 * axios自定义参数
 */
declare module 'axios' {
    interface AxiosRequestConfig {
        otherParams?: RequestOtherParamsType
    }
}

/**
 * 请求类
 */
class ProcessRequest implements ProcessRequestInterface {
    get(url: string, data?: any, otherParams?: RequestOtherParamsType) {
        return request({url: url, method: "GET", params: data, otherParams: otherParams})
    }

    post(url: string, data?: any, otherParams?: RequestOtherParamsType) {
        return request({url: url, method: "post", data: data, otherParams: otherParams})
    }

    put(url: string, data?: any, otherParams?: RequestOtherParamsType) {
        return request({url: url, method: "PUT", data: data, otherParams: otherParams})
    }

    delete(url: string, data?: any, otherParams?: RequestOtherParamsType) {
        return request({url: url, method: "DELETE", data: data, otherParams: otherParams})
    }
}

export default ProcessRequest